#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    int t;
    cin >> t;
    while (t--){
        int n, m, l, V;
        cin >> n >> m >> l >> V;
        int d[n+1], v[n+1], a[n+1], p[m+1], f1=1;
        for (int i=1; i<=n; i++){
            cin >> d[i] >> v[i] >> a[i];
            if (a[i] != 0)
                f1 = 0;
        }
        for (int i=1; i<=m; i++)
            cin >> p[i];
        sort(p+1, p+m+1);
        if (f1){
            int s=0;
            for (int i=1; i<=n; i++)
                if (v[i] > V && d[i] <= p[m])
                    ++s;
            cout << s << ' ' << 1 << '\n';
            continue;
        }
        int s1=0, ll[n+1];
        for (int i=1; i<=n; i++){
            int f=0;
            for (int j=1; j<=m; j++){
                if (p[j] >= d[i]){
                    if (sqrt(v[i]*v[i]+2*a[i]*(p[j]-d[i])) > V){
                        f = 1;
                        break;
                    }
                }
            }
            ll[i] = f;
            s1 += f;
        }
        cout << s1 << ' ';
        int s2=0;
        for (int i=0; i<(1<<m); i++){
            int w=0;
            for (int j=1; j<=n; j++){
                if (ll[j] == 0)
                    continue;
                int f=1;
                for (int k=1; k<=m; k++)
                    if (i & (1 << (k - 1)))
                        if (sqrt(v[j]*v[j]+2*a[j]*(p[k]-d[j])) > V)
                            f = 0;
                w += f;
            }
            s2 = max(s2, w);
        }
        cout << s2 << '\n';
    }
    return 0;
}
